{include file="admin@public/header" /}

<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">
<link href="/public/static/admin/blue/bills.css" rel="stylesheet" type="text/css">
<div class="wrapper">
  <div class="mod-toolbar-top mr0 cf dn" id="toolTop"></div>
  <div class="bills">
    <div class="con-header">
      <dl class="cf">
        <dd class="mr20">
          <label><span class="red">*</span>客户：</label>
          <span class="ui-combo-wrap" id="customer">
          <input type="text" name="" class="input-txt" autocomplete="off" value="" data-ref="date">
          <i class="ui-icon-ellipsis" onclick="chooseSupplier()"></i></span></dd>

        <dd class="mr20 tc">
          <label>总欠款:</label>
          <input type="text" id="cha_jine" value="0.00" class="ui-input ui-input-dis" disabled>
          <!-- <input type="hidden" id="totalArrearshidden" class="ui-input ui-input-dis"> -->
        </dd>
        <dd  class="mr10 tc" style="position: relative;">
          <label> &emsp;收款人:</label>
          <span class="ui-combo-wrap ui-combo-active" id="sales" style="width: 118px;">
            <input type="text" class="input-txt" autocomplete="off" style="width: 92px;" value="{$info.saler_name|default='空'}" id="staff_name"><i
              class="trigger" id="choose_staff"></i></span>
            {include file="admin@public/staff" /}
        </dd>
        <dd class="mr20">
          <label>单据日期：</label>
          <input type="date" id="dj_time" class="ui-input" value="{$today}" style="width: 125px;">
        </dd>
        <!-- <dd id="identifier" style="float:right">
          <label>单据编号：</label>
          <span id="number">SKD20210823004</span></dd> -->
        <dd id="identifier" style="float:right">
          <label>单据编号:</label>
          <span id="number">{$sn}</span>
          <i id="editBills"></i>
          <span class="ui-combo-wrap" id="numberAuto" style="display: none;">
            <i class="trigger"></i>
          </span>
        </dd>
      </dl>
      <hr class="hrcls" />
      <div class="cf  ">
        <div class="fl">
          <span  id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
        </div>
        <!-- <div class="fr">
          <span class="circle-link-order linkToCheck"><a href="#" class="icon-link-order"></a>历史单据</span>
        </div> -->
      </div>
    </div>
    <div class="grid-wrap mb10" id="acGridWrap">
      <table id="accountGrid">
      </table>
    </div>
    <div id="standardVersion">
        <div class="tr" style="margin:0 -10px 10px 0; "><a class="ui-btn" id="selectSource" onclick="chooseSource()">选择源单</a></div>
        <div class="grid-wrap" id="billGridWrap">
          <table id="grid">
          </table>
        </div>
        <div class="cf" id="bottomField">
                <span id="groupBtn">
                   
                    <a id="savaAndAdd" class="ui-btn ui-btn-sp">保存并新增</a>
                    <a id="save" class="ui-btn">保存</a>
                    <a id="shenhe" class="ui-btn">审核</a>
                </span>
            </div>
        <!-- <div class="con-footer cf">
            <label id="paymentTxt">整单折扣:</label>
            <input type="text" id="discount" class="ui-input">&emsp;
            <span>
            <label>本次预收款:</label>
            <input type="text" id="payment" class="ui-input ui-input-dis" disabled>
            </span>
        </div> -->
    </div>
    <!-- <div class="con-footer cf pt">
    		<div class="mb10">
	      	<div class="label-wrap">
	        	<label>备注:</label>
	        </div>
	        <div class="ctn-wrap">
	        	<input type="text" id="note" class="ui-input" data-ref="discount" style="width:100%; margin:0 -6px; ">
	        </div>
	      </div>
	</div> -->
   <div class="con-footer cf">
      <div class="mb10">
          <textarea type="text" id="note" class="ui-input ui-input-ph">暂无备注信息</textarea>
      </div>
      <ul id="amountArea" class="cf">
        <li>
          <label id="paymentTxt">整单折扣:</label>
          <input type="text" id="zk_jine" class="ui-input" value="0.00" onchange="zk_jine()">&emsp;
        </li>
        <li id="accountWrap">
          <label>本次预收款:</label>
          <input type="text" id="now_jine" class="ui-input ui-input-dis" value="0.00" disabled>
        </li>
      </ul>

      <div class="cf fr">
        <a href="#" class="linkToCheck ui-btn-bill ui-btn-add mr20" onclick="addPage('/money/receipt/index.html','money_receipt','收款单记录')">历史单据</a>
        <a href="#" id="operaLog" class="ui-btn">操作日志</a>
      </div> 
    </div>
    <div class="cf" id="bottomField">
      <div class="fr" id="toolBottom"></div>
    </div>
    <div id="mark"></div>
  </div>

</div>

<!--  以隐藏的方式获取商品的样式 ，作用是样式 -->
<div id="p_settle_type_id" style="display:none;"> </div>
<div id="p_account_id" style="display: none"></div>
<!--  以隐藏的方式获取商品的样式 ，作用是赋值 -->
<div style="display:none;">
    <input type="text" id="settle_type_name" value="" autocomplete="off" readonly="">
    <input type="text" id="account_name" value="" autocomplete="off" readonly="">
    <input type="text" id="user_id" value="" autocomplete="off" readonly="">
    <input type="text" id="hexiao_jine" value="0" autocomplete="off" readonly=""> 
    <input type="text" id="jine" value="0" autocomplete="off" readonly="">
    <!-- 真正的总欠款 -->
    <input type="text" id="real_qk" value="0" autocomplete="off" readonly=""> 
</div> 
 <!-- 结算账户弹窗 -->
  <div class="ui-droplist-wrap" id="account_wrap"  style="position: absolute; z-index: 1000; width: 102px;display:none;">
    <div class="droplist" id="account_list" style="position: relative; overflow: auto; min-height: 150px; height: 150px;">
      {volist name="account" id="vo"}
      <div class="list-item" account_id="{$vo.id}" title="{$vo.name}">{$vo.name}</div>
      {/volist}
    </div>
  </div>
 <!-- 结算方式 -->
  <div class="ui-droplist-wrap" id="settle_type_wrap"  style="position: absolute; z-index: 1000; width: 102px;display:none;">
    <div class="droplist" id="settle_type_list" style="position: relative; overflow: auto; min-height: 150px; height: 150px;">
      {volist name="settle_type" id="vo"}
      <div class="list-item" settle_type_id="{$vo.id}" title="{$vo.name}">{$vo.name}</div>
      {/volist}
    </div>
  </div>

<script type="text/javascript">
//鼠标移开时隐藏展开的列表
  $('#toolBottom').on('mouseleave.menuEvent','.ui-btn-menu', function(e){
    $(this).removeClass('ui-btn-menu-cur');
  });
  $('#toolBottom').on('mouseover','.ui-btn-menu', function(e){
    $(this).addClass('ui-btn-menu-cur');
  });
</script>


<script type="text/javascript">
    var a_edit_row = 0;
    var a_edit_col = 0;
    var a_row_id = 0;
    var a_col_name = 0;
    $(document).ready(function () {
        $("#accountGrid").jqGrid({
            // url: '/admin/store/index.html?ajax=100',
            datatype: "local",//数据来源，本地数据（local，json,jsonp,xml等）
            height: '90%',//高度，表格高度。可为数值、百分比或'auto'
            colNames: ['<span class="red">*</span>结算账户','<span class="red">*</span>收款金额', '结算方式', '结算号', '备注', '结算账户ID', '结算方式id'],
            colModel: [
               // { name: '', width: 70,},
                {
                    name: "account_name",
                    width: 100,
                    link: "inventory",
                    editable: true,
                    edittype: "custom",
                    editoptions: {
                    custom_element: function (t, e) {
                        $("#p_account_id").html('<div class="pr" id="account_id"><input type="text" value="'+t+'" class="textbox storageAuto customelement ui-combo-active" autocomplete="off" style="outline: -webkit-focus-ring-color auto 5px;"><span class="ui-icon-triangle-1-s" id="account_id1"></span></div>');
	                      return $("#account_id");
	                    },
	                    custom_value: function (t, e, a) {
	                      var ba = $("#account_name").val();
	                      $("#account_name").val("");
	                      return ba;
	                    },

	                    trigger: "ui-icon-triangle-1-s"
                    }
                },

                { name: 'jine', width: 100,editable: true, editoptions: {
                    size: 25,
                    dataEvents: [
                      {
                        type: 'change',     //blur,focus,change............. 
                        fn: function (e) {
                          a_reload_val();
                        }
                      }
                    ]
                  }
                },
               {
                  name: "settle_type_name",
                  width: 100,
                 // link: "inventory",
                  editable: true,
                  edittype: "custom",
                  editoptions: {
                    custom_element: function (t, e) {
                      $("#p_settle_type_id").html('<div class="pr" id="settle_type_id"><input type="text" value="'+t+'" class="textbox storageAuto customelement ui-combo-active"  autocomplete="off" style="outline: -webkit-focus-ring-color auto 5px;"><span class="ui-icon-triangle-1-s" id="settle_type_id1"></span></div>');
                      return $("#settle_type_id");
                    },
                    custom_value: function (t, e, a) {
                      var ba = $("#settle_type_name").val();
                      $("#settle_type_name").val("");
                      return ba;
                    },

                    trigger: "ui-icon-triangle-1-s"
                  }
                },
                { name: 'settle_sn', width: 100, editable: true},
                { name: 'mark',  width: 150, editable: true },
                { name: 'account_id',  hidden: true },
                { name: 'settle_type_id', hidden: true },
            ],
            cellEdit: true,
            cellurl: '/',
            sortname: 'id',
            sortorder: "desc",
            rownumbers: true, //自增序号
          
            altRows: !0,
            gridview: !0,
            shrinkToFit: !1,
            cellLayout: 8,
            autowidth: !0,
            pager: "#page",
            viewrecords: !0,
            cmTemplate: {
                sortable: !1,
                title: !1
            },
            // 合计
            footerrow: true,
            loadError: function (t, e, i) {
                parent.Public.tips({
                    type: 1,
                    content: "操作失败了哦，请检查您的网络链接！"
                })
            },
            beforeEditCell: function (rowid, cellname, value, iRow, iCol) {
                a_col_name = cellname;
                a_edit_row = iRow;
                a_edit_col = iCol;
                a_row_id = rowid;
                var aname = $("#accountGrid").jqGrid("getCell", a_row_id, 'account_name');
                $("#account_name").val(aname);
                var bname = $("#accountGrid").jqGrid("getCell", a_row_id, 'settle_type_name');
                $("#settle_type_name").val(bname);
            },
            gridComplete: function () {
              // 合计的变量
              var jines = $("#accountGrid").getCol('jine', false, 'sum');
              $("#jine").val(jines);//付款总金额
              $("#accountGrid").footerData('set', { "account_name": '合计：', jine: jines,});
            },
        });

        var mydata = [];
        for (var i = 0; i < 3; i++) {
            var obj = { id: i + 1, account_money: "0",settle_sn:"",mark:""}
            mydata.push(obj);
        }
        for (var i = 0; i <= mydata.length; i++) {
            jQuery("#accountGrid").jqGrid('addRowData', i + 1, mydata[i]);
        }


    });
    
</script>
<script type="text/javascript">
    $(document).ready(function () {
        // 选择结算账户-弹窗
        $(".grid-wrap").on("click", "#account_id1", function (e) {
            var top = $(this).offset().top;
            var left = $(this).offset().left;
            $("#account_wrap").slideToggle();
            $("#account_wrap").css({ "top": (top + 22) + "px", "left": (left - 78) + "px" })
        })
        //选择结算账户-赋值
        $("#account_wrap #account_list").on("click", ".list-item", function (e) {
            var title = $(this).attr("title");
            //结算账户
            if (a_col_name == "account_name") {
                var account_id = $(this).attr("account_id");
                $("#account_name").val(title);
                $("#accountGrid").jqGrid("setCell", a_row_id, 'account_id', account_id);
                $("#accountGrid").jqGrid("setCell", a_row_id, 'account_name', title);//及时保存
                $("#accountGrid").jqGrid("saveCell", a_edit_row, a_edit_col);//保存数据表格
            }
            $("#accountGrid").saveRow(a_row_id, false);
            $("#account_wrap").hide();
        });
    })
     //选择结算账户-选择框外点击则隐藏
    $(document).mouseup(function (e) {
        if(e.target.id!="account_id1"){
            var con = $("#account_wrap");   // 设置目标区域
            if (!con.is(e.target) && con.has(e.target).length === 0) {
                 $("#account_wrap").hide();
            }
        } 
    });

    $(document).ready(function () {
        // 选择结算方式-弹窗
        $(".grid-wrap").on("click", "#settle_type_id1", function (e) {
            var top = $(this).offset().top;
            var left = $(this).offset().left;
            $("#settle_type_wrap").slideToggle();
            $("#settle_type_wrap").css({ "top": (top + 22) + "px", "left": (left - 78) + "px" })
        })
        //选择结算方式-赋值
        $("#settle_type_wrap #settle_type_list").on("click", ".list-item", function (e) {
            var title = $(this).attr("title");
            //结算方式
            if (a_col_name == "settle_type_name") {
                var settle_type_id = $(this).attr("settle_type_id");
                $("#settle_type_name").val(title);
                $("#accountGrid").jqGrid("setCell", a_row_id, 'settle_type_id', settle_type_id);
                $("#accountGrid").jqGrid("setCell", a_row_id, 'settle_type_name', title);//及时保存
            }
            $("#accountGrid").saveRow(a_row_id, false);
            $("#settle_type_wrap").hide();
        });
    })
     //选择结算方式-选择框外点击则隐藏
    $(document).mouseup(function (e) {
        if(e.target.id!="settle_type_id1"){
            var con = $("#settle_type_wrap");   // 设置目标区域
            if (!con.is(e.target) && con.has(e.target).length === 0) {
                 $("#settle_type_wrap").hide();
            }
        } 
    });

</script>
<script type="text/javascript">
	 //选择客户(供应商)
     function chooseSupplier() {
        layer.open({
          type: 2,
          title: "选择客户",
          shadeClose: true,
          shade: 0.3,
          maxmin: false, //开启最大化最小化按钮
          area: ['775px', '510px'],
          fixed: false, //不固定
          btn: ['确定', '取消'],
          content: "/admin/basic/choose_customer.html?single=1&is_customer=1",//单选，客户
          btn1: function (index, layero) {
            var body = layer.getChildFrame('body', index);
            //var supplierid = body.find('input[name="goodid"]:checked').val();
            var id =  body.find("#grid").jqGrid('getGridParam','selrow');
            if (id == '' || id == null) {
              layer.msg("请选择客户");
              return false;
            } else {
              //获取商品信息
              $.get("/admin/basic/one_customer.html", { id: id }, function (data, state) {
                if (data.status == 1) {
                  $("#customer input").val(data.info.sn + " " + data.info.name);
                  $('#user_id').val(data.info.id);
                  $('#cha_jine').val(data.info.user_arrears);//总欠款
                  $('#real_qk').val(data.info.user_arrears);//真实总欠款
                  layer.close(index);
                } else {
                  layer.msg("获取商品信息失败");
                }
              })
            }
            layer.close(index);
            return false;
          },
          btn4: function (index, layero) {
            layer.close(index);
            return false;
          }
        })
      }
</script>
<script type="text/javascript">


    // 选择源单
    function chooseSource(){
      	var user_id = $("#user_id").val();//客户ID
       	if (user_id == "") {
      		layer.msg("请选择客户");
      		return false;
    	}

    	chooseSource_order('/admin/basic/choose_source_list.html?user_id='+user_id, this, function (res) {
	      	if (res.btn == 1 && res.status == 1) {
		        var data = res.data;
		        var source_arr=res.data.info;
		        if (data.status == 1) {
					//赋值
		        	//console.log(source_arr);
		        	$("#grid").jqGrid("clearGridData");
					for(var i = 0;i<source_arr.length;i++){
						//$("#grid").setGridParam({cellEdit:false});
						var rowData ={
							'psn': source_arr[i].sn,
							'type_name': source_arr[i].o_type_name,
							'dj_time': source_arr[i].dj_time,
							'jine': source_arr[i].dj_jine,
							'already_jine': source_arr[i].already_jine,
							'not_jine': source_arr[i].not_jine,
							'now_jine': source_arr[i].dj_jine,
							'mark': source_arr[i].mark,
							'oid':source_arr[i].id,
              'type': source_arr[i].o_type,
						}
						$("#grid").jqGrid("addRowData", i, rowData);

						//$("#grid").jqGrid('setCell', i, 'now_jine', '', 'edit-cell');//设置单元格可以编辑
						//$("#grid").jqGrid().trigger("reloadGrid");
					}
					//不足5条则补充
					if(5-source_arr.length>0){
						for (var ii = 0; ii < 5-source_arr.length; ii++) {
					        $("#grid").jqGrid('addRowData', source_arr.length+ii+1, { id: ii + 1, oid: 0});
					    }
					}
		        } else {
		          layer.msg("获取信息失败");
		        }
	    	}
		});
    }

</script>
<script type="text/javascript">
    var edit_row = 0;
    var edit_col = 0;
    var row_id = 0;
    var col_name = 0;
    $(document).ready(function () {

        $("#grid").jqGrid({
            // url: '/admin/store/index.html?ajax=100',
            datatype: "local",//数据来源，本地数据（local，json,jsonp,xml等）
            height: '90%',//高度，表格高度。可为数值、百分比或'auto'
 
 			colNames: ['源单编号','业务类别', '单据日期', '单据金额', '已核销金额', '未核销金额', '<span class="red">*</span>本次核销金额','单据备注','ID','TYPE'],
            colModel: [
                { name: 'psn', width: 150},
                { name: 'type_name', width: 100},
                { name: 'dj_time', width: 100},
                { name: 'jine', width: 100},
                { name: 'already_jine', width: 100},
                { name: 'not_jine', width: 100},
                { name: 'now_jine', width: 100,editable: true, editoptions: {
                    size: 25,
                    dataEvents: [
                      {
                        type: 'change',     //blur,focus,change............. 
                        fn: function (e) {
                          reload_val();
                        }
                      }
                    ]
                  }
                },
                { name: 'mark', width: 400},
                { name: 'oid', hidden:true},
                { name: 'type', hidden:true},
            ],

            cellEdit: true,
            cellurl: '/',
            rowNum: 10,
            rowList: [10, 20, 30],
            sortname: 'id',
            sortorder: "desc",
            pagerpos: "left",//分页位置

            pgbuttons: true,//翻页按钮
            pagination: true,
            altRows: !0,
            gridview: !0,
            shrinkToFit: !1,
            cellLayout: 8,
            autowidth: !0,
            pager: "#page",
            viewrecords: !0,
            rownumbers: true, //自增序号
            cmTemplate: {
                sortable: !1,
                title: !1
            },
            // 合计
            footerrow: true,
            loadError: function (t, e, i) {
                parent.Public.tips({
                    type: 1,
                    content: "操作失败了哦，请检查您的网络链接！"
                })
            },
            beforeEditCell: function (rowid, cellname, value, iRow, iCol) {
                col_name = cellname;
                edit_row = iRow;
                edit_col = iCol;
                row_id = rowid;
            },
            gridComplete: function () {
              // 合计的变量
              var jines = $("#grid").getCol('jine', false, 'sum');
              var already_jines = $("#grid").getCol('already_jine', false, 'sum');
              var not_jines = $("#grid").getCol('not_jine', false, 'sum');
              var now_jines = $("#grid").getCol('now_jine', false, 'sum');
              $("#hexiao_jine").val(now_jines);//核销总金额
         
              
              var user_arrears= $('#real_qk').val();//真实总欠款
              var zk_jine = $('#zk_jine').val();//整单折扣
              var jine= $("#jine").val();//付款总金额
              $('#cha_jine').val(parseFloat(user_arrears)-parseFloat(not_jines)-parseFloat(zk_jine)-parseFloat(jine));//总欠款=真实总欠款-折扣-付款总金额-未核销总金额
              $("#now_jine").val(parseFloat(not_jines)-parseFloat(now_jines)+parseFloat(zk_jine)+parseFloat(jine));//本次预收款=未核销-本次核销+折扣+付款总金额
              $("#grid").footerData('set', { "psn": '合计：', jine: jines,already_jine:already_jines,not_jine:not_jines,now_jine:now_jines});
              //改变折扣-打几折
              // var $j = $("#accountGrid").jqGrid("getCell", 1, 'jine');//
              // var $jj = $("#grid").jqGrid("getCell", 1, 'oid');//
              // console.log($j);
              // console.log($jj);
             
              // if($j==null&&$jj!=0){
              //     $("#accountGrid").jqGrid("setCell", 1, 'jine',now_jines );//折扣额
              //     $("#accountGrid").jqGrid().trigger("reloadGrid");
              // }
           
            },
        });

        var mydata = [];
        for (var i = 0; i < 5; i++) {
            var obj = { id: i + 1, goodsname: "", dw: "" ,good_id:"0",mark:""}
            mydata.push(obj);
        }
        for (var i = 0; i <= mydata.length; i++) {
            jQuery("#grid").jqGrid('addRowData', i + 1, mydata[i]);
        }


    });
    
</script>

<script type="text/javascript">

  function reload_val() {
    var rid = row_id;
    var c_name = col_name;
    if (c_name == "now_jine") {
          // 合计的变量
        var jines = $("#grid").getCol('jine', false, 'sum');
        var already_jines = $("#grid").getCol('already_jine', false, 'sum');
        var not_jines = $("#grid").getCol('not_jine', false, 'sum');
        var now_jines = $("#grid").getCol('now_jine', false, 'sum');
  
        $("#hexiao_jine").val(now_jines);//核销总金额
        var user_arrears= $('#real_qk').val();//真实总欠款
        var zk_jine = $('#zk_jine').val();//整单折扣
        var jine= $("#jine").val();//付款总金额

        $('#cha_jine').val(parseFloat(user_arrears)-parseFloat(not_jines)-parseFloat(zk_jine)-parseFloat(jine));//总欠款=真实总欠款-折扣-付款总金额-未核销总金额
        $("#now_jine").val(parseFloat(not_jines)-parseFloat(now_jines)+parseFloat(zk_jine)+parseFloat(jine));//本次预收款=未核销-本次核销+折扣+付款总金额
        $("#grid").footerData('set', { "psn": '合计：', jine: jines,already_jine:already_jines,not_jine:not_jines,now_jine:now_jines});
    } 


  }

  function a_reload_val() {
    var a_rid = a_row_id;
    var a_c_name = a_col_name;
    if (a_c_name == "jine") {
        // 合计的变量
        var jines = $("#accountGrid").getCol('jine', false, 'sum');
        $("#jine").val(jines);//付款总金额
        $("#accountGrid").footerData('set', { "account_name": '合计：', jine: jines,});
    } 
  }
  
   //整单折扣改变
  function zk_jine() {

    var not_jines = $("#grid").getCol('not_jine', false, 'sum');//未核销总金额
    var now_jines = $("#grid").getCol('now_jine', false, 'sum');//本次核销总金额
   
    $("#hexiao_jine").val(now_jines);//核销总金额
    var user_arrears= $('#real_qk').val();//真实总欠款
    var zk_jine = $('#zk_jine').val();//整单折扣
    var jine= $("#jine").val();//付款总金额
     //alert(jine);
    $('#cha_jine').val(parseFloat(user_arrears)-parseFloat(not_jines)-parseFloat(zk_jine)-parseFloat(jine));//总欠款=真实总欠款-折扣-付款总金额-未核销总金额
    $("#now_jine").val(parseFloat(not_jines)-parseFloat(now_jines)+parseFloat(zk_jine)+parseFloat(jine));//本次预收款=未核销-本次核销+折扣+付款总金额
  }
</script>
<script type="text/javascript">
  var grid = $('#grid');
  var accountGrid=$('#accountGrid');
  $(".wrapper").on("click", "#savaAndAdd", function (e) {
    //先保存
    save_jqgrid(a_edit_row,a_edit_col,accountGrid,function (res1) {
      save_jqgrid(edit_row,edit_col,grid,function (res) {
        savedata();
      });
    });
  })

  function savedata() {
    var gooddata = $('#grid').jqGrid('getGridParam', 'data');
    var accountdata = $('#accountGrid').jqGrid('getGridParam', 'data');
    //console.log(gooddata);
    var flag = 0;
    var hasuser = 0;
    var jine=0;
    var indexArr = [];
    accountdata.forEach(function (self, index) {
      //console.log(self);
      if (self['account_id'] != null ) {
        hasuser = 1;
        if (self['jine'] == null || self['jine'] == "") {
          flag = 1;
          indexArr.push(index);
        }else{
          jine=jine+parseFloat(self['jine']);//实付金额
        }
      }
    });
    if (hasuser == 0) {
      layer.msg("请选择结算账户");
      // 必填项（结算账户）
      $("#accountGrid").editCell(1, 1, true);
      return false;
    }

    if (flag == 1) {
      layer.msg("请填写收款金额");
      // 必填项（收款金额）
      $("#accountGrid").editCell(indexArr[0] + 1, 2, true);
      return false;
    }

    var user_id = $("#user_id").val();//客户ID
    if (user_id == "") {
      layer.msg("请选择用户");
      return false;
    }
    var staff_id = $("#staff_id").val();//收款人
    var dj_time = $("#dj_time").val();//单据日期
    var sn = $("#number").html();//单据号
    var mark = $("#note").val();//备注
    var zk_jine = $("#zk_jine").val();//整单折扣
    var now_jine = $("#now_jine").val();//本次预收款
    var cha_jine = $("#cha_jine").val();//总欠款
    var hexiao_jine = $("#hexiao_jine").val();//核销的总金额
    //return false;
    $.ajax({
      type: 'POST',
      url: "save.html",
      data: { saler:staff_id,user_id: user_id, sn: sn, mark: mark, gooddata: gooddata,accountdata:accountdata, dj_time: dj_time,zk_jine:zk_jine,now_jine:now_jine,cha_jine:cha_jine,hexiao_jine:hexiao_jine,jine:jine},
      dataType: "json",
      async: false,
      error: function (request) {
        layer.msg("发送请求失败！");
      },
      success: function (data) {
        if (data.status == 1) {
          layer.msg(data.msg);
        } else {
          layer.msg(data.msg);
        }

      }
    });

  }

  $(".wrapper").on("click", "#save", function (e) {
    save_jqgrid(a_edit_row,a_edit_col,accountGrid,function(res1){
      save_jqgrid(edit_row,edit_col,grid,function(res){
         $("#accountGrid").jqGrid().trigger("reloadGrid");
          $("#grid").jqGrid().trigger("reloadGrid");
        layer.msg("保存成功");
      });
    });
  })

</script>
{include file="admin@public/footer" /}